import { defineStore } from 'pinia'

export const useChannelStore = defineStore<'channel', any, any>('channel', {
  state: () => ({
    SystemInfo: {
      tenantId: '',
      openRobot: false, // 机器是否开启
      backgroundImage: '', // 背景图
      browserTitle: '', // 浏览器标题
      isStrongAuth: false, // 是否开启强认证
      // 拒识转人工
      refuseTransferLabor: 2,
      robotChannelId: '',
    },
    Evaluate: {},
    upload: [],
    uploadType: '',
  }),
  actions: {
    setUploadType(data: any) {
      this.uploadType = data
    },
    // 上传配置
    setUpload(data: any) {
      this.upload = data
    },
    // 修改用户详情
    updataUserInfo(data: any) {
      this.UserInfo = data
    },
    // 修改系统信息
    updateSystemInfo(data: any) {
      this.SystemInfo[data.key] = data.value
    },
    // 设置评价信息
    setEvaluateRate(data: any) {
      this.Evaluate.rate = data
    },
    setEvaluateSelect(data: any) {
      this.Evaluate[data.key] = data.value
    },
  },
  getters: {
    uploadInfo: (state) => {
      return state.upload
    },
    systemInfo: (state) => {
      return state.SystemInfo
    },
    // 机器人头像
    robotAvatar: (state) => {
      return state.SystemInfo.backgroundImage
    },
    // 坐席头像
    agentAvatar: (state) => {
      return state.SystemInfo.avatar
    },
    // 访客头像
    visitorAvatar: (state) => {
      return state.SystemInfo.visitorAvatar
    },
    evaluate: (state) => {
      return state.Evaluate
    },
  },
  persist: {
    key: 'channel', //存储名称
    storage: localStorage, // 存储方式
    serializer: {
      serialize: (value) => JSON.stringify(value),
      deserialize: (value) => JSON.parse(value),
    },
    beforeHydrate: () => {}, // 从 storage 恢复数据之前触发
    afterHydrate: () => {}, // 从 storage 恢复数据之后触发
    omit: ['messages'], // 默认不持久化
    pick: ['SystemInfo', 'Evaluate'], // 默认持久化
  },
})
